package com.bolt.auth.admin.api.sys.entity;

/**
 * @author 米超
 * 角色信息
 */

import com.bolt.support.spring.jpa.entity.BaseUuidAuditingEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.List;


@Access(AccessType.FIELD)
@Entity
@Table(name = "SYS_ROLE")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@DynamicInsert
@DynamicUpdate
@Data
public class RoleEntity extends BaseUuidAuditingEntity {

    private static final long serialVersionUID = 8349095184009720763L;

    @Size(min = 6)

    @Column(nullable = false, length = 64, unique = true)
    private String code;

    @Column(nullable = false, length = 256)
    private String name;

    @Column(nullable = true, length = 2000)
    private String description;

    @Column(name = "ENABLED", length = 1)
    private Boolean enabled;

    @Enumerated(EnumType.STRING)
    private DataScopeEnum dataScope;

    @ManyToMany
    @JoinTable(name = "SYS_ROLER2ORG",
            joinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "org_id",referencedColumnName = "id")})
    private List<OrgEntity> orgs;

    @OneToMany(mappedBy = "role", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
    @JsonIgnore
    private List <RoleR2Privilege> roleR2Privileges = new ArrayList();

    @OneToMany(mappedBy = "role", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
    @JsonIgnore
    private List <UserR2Role> roleR2Users = new ArrayList();




}
